using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Oops.Xna.Framework
{
	public struct Quadrilateral
	{
		private VertexPositionNormalTexture[] vertices;
		private int[] indices;

		public Quadrilateral(Vector3 origin, Vector3 normal, Vector3 up, float width, float height, int repeatX, int repeatY)
		{
			this.vertices = new VertexPositionNormalTexture[4];
			this.indices = new int[6];

			normal.Normalize();
			up.Normalize();
			Vector3 left = Vector3.Cross(normal, up);

			Vector3 upperCenter = (up * height * 0.5f) + origin;

			// Set the position, normal and texture coordinate for each vertex.
			this.vertices[0].Position = upperCenter + (left * width * 0.5f) - (up * height);
			this.vertices[0].Normal = normal;
			this.vertices[0].TextureCoordinate = new Vector2(0.0f, repeatY);

			this.vertices[1].Position = upperCenter + (left * width * 0.5f);
			this.vertices[1].Normal = normal;
			this.vertices[1].TextureCoordinate = new Vector2(0.0f, 0.0f);

			this.vertices[2].Position = upperCenter - (left * width * 0.5f) - (up * height);
			this.vertices[2].Normal = normal;
			this.vertices[2].TextureCoordinate = new Vector2(repeatX, repeatY);

			this.vertices[3].Position = upperCenter - (left * width * 0.5f);
			this.vertices[3].Normal = normal;
			this.vertices[3].TextureCoordinate = new Vector2(repeatX, 0.0f);

			// Set the index buffer for each vertex, using clockwise winding.
			this.indices[0] = 0;
			this.indices[1] = 1;
			this.indices[2] = 2;
			this.indices[3] = 2;
			this.indices[4] = 1;
			this.indices[5] = 3;
		}

		public VertexPositionNormalTexture[] Vertices
		{
			get { return this.vertices; }
		}

		public int[] Indices
		{
			get { return this.indices; }
		}
	}
}
